package ${basePkg}.mvc;

import ${basePkg}.domain.${className};
import ${basePkg}.query.${className}QueryObject;
import ${basePkg}.service.I${className}Service;
import ${basePkg}.util.RequiredPermission;
import com.opensymphony.xwork2.interceptor.annotations.InputConfig;

import java.io.IOException;

public class ${className}Action extends BaseAction{
	/**
	 * 
	 */
	private I${className}Service ${objectName}Service;
	
	
	private ${className} ${objectName} = new ${className}();
	
	public ${className} get${className}() {
		return ${objectName};
	}
	public void set${className}(${className} ${objectName}) {
		this.${objectName} = ${objectName};
	}
	private ${className}QueryObject queryObject = new ${className}QueryObject();
	
	
	public ${className}QueryObject getQueryObject() {
		return queryObject;
	}
	public void setQueryObject(${className}QueryObject queryObject) {
		this.queryObject = queryObject;
	}
	public void set${className}Service(I${className}Service ${objectName}Service) {
		this.${objectName}Service = ${objectName}Service;
	}
	@InputConfig(methodName = "input")
	@RequiredPermission(value="${className}列表")
	public String execute() {
		putContext(PAGERESULT, ${objectName}Service.query(queryObject));
		
		return LIST;
	}
	@RequiredPermission(value="新增/修改${className}")
	public String input() {
		if(${objectName}.getId()!=null) {
			${objectName} = ${objectName}Service.get(${objectName}.getId());
		}
		return INPUT;
	}
	@RequiredPermission(value="修改${className}")
	public String saveOrUpdate() {
		try {
			if(${objectName}.getId()!=null) {
                ${objectName}Service.update(${objectName});
                addActionMessage("修改成功");
            }else {
                ${objectName}Service.save(${objectName});
                addActionMessage("保存成功");
            }
		} catch (Exception e) {
			e.printStackTrace();
			addActionError(e.getMessage());
		}
		return SUCCESS;
	}
	public void prepareSaveOrUpdate(){
		if(${objectName}.getId()!=null) {
			${objectName} = ${objectName}Service.get(${objectName}.getId());
			
		}
	}
	@RequiredPermission(value="删除${className}")
	public String delete() throws IOException{
		${objectName}Service.delete(${objectName});
		putResponseText("删除成功");
		return NONE;
	}
	
	

}
